package com.project.export

import org.apache.spark.SparkConf
import org.apache.spark.sql.{SaveMode, SparkSession}

object topten_universities_majors {
  def main(args: Array[String]): Unit = {
    //-1. spark 配置对象
    val sparkConf = new SparkConf()
      .setMaster("local[*]")
    //-2. sparksession对象
    val sparkSession = SparkSession
      .builder()
      .config(sparkConf)
      .enableHiveSupport() //-:开启hive的支持
      .appName("postgraduateInformation")
      .getOrCreate()
    val df_all = sparkSession.sql(
      "select school_name,count(distinct professional_code) as total_majors from final_project.dwd_postgraduate_information group by school_name order by total_majors desc limit 10")
    df_all.write
      .format("jdbc")
      .option("url", "jdbc:mysql://192.168.75.104:3306/finalProject")
      .option("user", "root")
      .option("password", "123456")
      .option("dbtable", "topten_universities_majors")
      .mode(SaveMode.Append)
      .save()


  }

}
